---
import { formatTimestamp, type PostWithUser, replaceShortenedUrls } from '../util/post.js';

const post: PostWithUser = replaceShortenedUrls(Astro.props.data);
---

<style>
  .text {
    color: var(--sl-color-text-accent);
  }
  .n .name,
  .engagement > * {
    margin-top: 0 !important;
  }
  header {
    display: flex;
    align-items: center;
    line-height: 1.3;
  }
  .n .profile {
    border-radius: 9999px;
    width: 48px;
    height: 48px;
  }
  .n {
    display: flex;
    gap: 1rem;
  }
  .n .name {
    display: flex;
    flex-direction: column;
  }
  .engagement {
    display: flex;
    align-items: center;
    justify-content: space-around;
    color: #595959;
  }
  .engagement > * {
    display: flex;
    gap: 0.5rem;
    white-space: nowrap;
    align-items: center;
  }
  .engagement svg {
    fill: currentColor;
  }
</style>

{
  post && (
    <>
      <header class="n">
        <img class="profile" src={post.user.profile_image_url} />
        <div class="name">
          <span class="real">{post.user.name}</span>
          <span class="screen">@{post.user.username}</span>
        </div>
      </header>
      <p class="text" set:html={post.text.trim().replace(/\n/g, '<br />')} />
      <p class="timestamp">
        <a
          href={`${post.url ? post.url : post.id.length > 17 ? `https://twitter.com/${post.user.username}/status/${post.id}` : `https://bsky.app/profile/${post.user.username}/post/${post.id}`}`}>
          {formatTimestamp(post.created_at)}
        </a>
      </p>
    </>
  )
}
